<!-- 合同通用查看弹窗 -->
<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" width="850">
    <el-radio-group v-model="activeTab">
      <el-radio-button value="1">合同签署</el-radio-button>
      <el-radio-button value="2">签署日志</el-radio-button>
    </el-radio-group>
    <!-- 审核信息 -->
    <div v-show="activeTab === '1'">
      <div class="mt-10" style="height: 550px;">
        <iframe style="width: 100%;height: 100%" :src="ctrInfo.ctrFileUrl" frameborder="0"></iframe>
      </div>
    </div>
    <!-- 审核日志  -->
    <div v-show="activeTab === '2'">
      <div v-if="reviewRecord.length">
        <div class="pb-4 pt-4 mt-2 mb-2 ml-2" style="border-bottom: 1px solid #eee;" v-for="(item,index) in reviewRecord" :key="index">
          <div>
            <span class="mr-10">{{ formatToDateTime(item.createTime) }}</span>
            <span class="mr-10">{{ item.operatorId }}{{ item.status == 2 ? '审核拒绝' : '审核通过'}}</span>
          </div>
          <div class="mt-3" v-if="item.remark">审核备注：{{ item.remark }}</div>
        </div>
      </div>
      <el-empty v-else description="暂无日志" />
    </div>
    <template #footer v-if="activeTab === '1'">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="handleSign" v-if="ctrInfo.signStatus == 0"  v-hasPermi="['ctr:info:sign']"> 签署</el-button>
    </template>
  </Dialog>
</template>
<script lang="ts" setup>
import {ElMessage} from 'element-plus'
import { crtInfoGet,crtInfoSign } from '@/api/contract/ctrInfo'
import {formatToDateTime} from '@/utils/dateUtil'
const message = useMessage() // 消息弹窗
const dialogTitle = ref('查看合同')
const dialogVisible = ref(false)  
const activeTab = ref('1')
const remark = ref('')  /// 审核备注
const ctrNo = ref('')

interface LogVo {
  createTime: number;
  ctrNo: string
  operatorId: number
  remark: string
  status: number
}
const ctrInfo = ref<any>({})
const reviewRecord = ref<LogVo[]>([])   // 审核日志
function open(_id: string,_ctrNo: string) {
  dialogVisible.value = true
  ctrNo.value = _ctrNo
  getCtrInfo(_id)
  // getTplReviewRecord(_ctrNo)
}

function close() {
  dialogVisible.value = false
} 

// 获取合同信息
async function getCtrInfo(id) {
  const params = {
    id
  }
  const res = await crtInfoGet(params)
  console.log('getTplReviewRecord',res)
  ctrInfo.value = res
}
// 获取记录
// const getTplReviewRecord = async (ctrNo: string) => { 
//   const params = {
//     pageNo: 1,
//     pageSize: 10,
//     ctrNo: ctrNo,
//   }
//   const res = await operatorLog(params)
//   console.log('getTplReviewRecord',res)
//   reviewRecord.value = res.list
// }
// 合同签署
const handleSign = async (status: number) => { 
  await message.confirm('确认签署该合同吗？')
  const params = {
    ctrNo: ctrNo.value,
  }
  const res = await crtInfoSign(params)
  console.log('res====',res)
  ElMessage.success('签署成功')
  close()
  emit('success')
}
/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
defineExpose({
  open,
})  
</script>
<style lang="scss" scoped> 

</style>
